﻿@using ABC.Controllers.ViewModels.My.Partners.Admin
@using ABC.Core.Extentions
@model AddPartnerViewModel
@{
    ViewBag.Title = "Добавление партнера - Азбука24";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
    var pagesize = Request.Params["pagesize"];
    var ppagesize = Request.Params["ppagesize"];
}
<script type="text/javascript">
    var AddingOffices = [];
    var DeleteOfficesId = [];
    function FormSubmit() {
        var postform = document.getElementById("form1");
        postform.appendChild(CreateHiddenField('FullName', $("#FullName").val()));
        postform.appendChild(CreateHiddenField('TypeOwnership', $("#TypeOwnership").val()));
        postform.appendChild(CreateHiddenField('PhoneRequisite', $("#PhoneRequisite").val()));
        postform.appendChild(CreateHiddenField('FaxRequisite', $("#FaxRequisite").val()));
        postform.appendChild(CreateHiddenField('JuridicalAddress', $("#JuridicalAddress").val()));
        postform.appendChild(CreateHiddenField('ActualAddress', $("#ActualAddress").val()));
        postform.appendChild(CreateHiddenField('Inn', $("#Inn").val()));
        postform.appendChild(CreateHiddenField('Kpp', $("#Kpp").val()));
        postform.appendChild(CreateHiddenField('Okpo', $("#Okpo").val()));
        postform.appendChild(CreateHiddenField('PaymentAccount', $("#PaymentAccount").val()));
        postform.appendChild(CreateHiddenField('CorrespondentAccount', $("#CorrespondentAccount").val()));
        postform.appendChild(CreateHiddenField('Bik', $("#Bik").val()));
        postform.appendChild(CreateHiddenField('offices', JSON.stringify(AddingOffices)));
        postform.appendChild(CreateHiddenField('deleteOfficesId', JSON.stringify(DeleteOfficesId)));
        postform.submit();
    }

    function DeleteProduct(obj) {
        var chk = $(obj).parents("tr").children("td").children("input[type='checkbox']");
        var postform = document.createElement('form');
        postform.action = '@Url.Action("DeleteProduct", "Admin")';
        postform.method = 'post';
        postform.acceptCharset = 'utf-8';
        postform.appendChild(CreateHiddenField('productId', chk.val()));
        postform.appendChild(CreateHiddenField('partnerId', '@Model.Id'));
        document.body.appendChild(postform);
        postform.submit();
    }

    function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                $('#avatar').attr("src", "http://placehold.it/250x290");
                $('#avatar')
                        .attr('src', e.target.result);
                if ($('#avatar').height() > 290) {
                    $('#avatar').css("height", "290px");
                }
            };
            reader.readAsDataURL(input.files[0]);
        }
    };

    function Office(data) {
        this.Id = ko.observable(data.Id);
        this.Name = ko.observable(data.Name);
        this.Type = ko.observable(data.Type);
        this.Phone = ko.observable(data.Phone);
        this.PhoneDob = ko.observable(data.PhoneDob);
        this.Fax = ko.observable(data.Fax);
        this.FaxDob = ko.observable(data.FaxDob);
        this.Address = ko.observable(data.Address);
    }

    function ChangePageSize() {
        location.href = '@Url.Action("FormPartner", "Admin", new { id = Model.Id })' + "?page=" + '@Model.PageNumber' + ($("#PageSize").val() != '@Model.ListForPageSize.First().Value' ? "&pagesize=" + $("#PageSize").val() : "") +
            ('@Model.PageNumberProducts' != '1' ? "&ppage=" + '@Model.PageNumberProducts' : "") + ($("#PPageSize").val() != '@Model.ListForPageSize.First().Value' ? "&ppagesize=" + $("#PPageSize").val() : "");
    }

    function MyViewModel() {
        var self = this;
        self.offices = ko.observableArray([""]);
        self.currentOfficeId = ko.observable("");
        self.isNewOffice = ko.observable(false);
        self.CountNewAddingOffice = ko.observable(1);

        self.addOffices = function () {
            var offs = JSON.parse('@Html.Raw(Model.Offices)');
            self.offices.removeAll();
            for (var i = 0; i < offs.length; i++) {
                self.offices.push(new Office(offs[i]));
            }
        };

        self.addOffice = function () {
            var office = new Object();
            office.Name = $("#office-name").val();
            office.Type = $("#office-type").val();
            office.Phone = $("#office-phone").val();
            office.PhoneDob = $("#office-phonedob").val();
            office.Fax = $("#office-fax").val();
            office.FaxDob = $("#office-faxdob").val();
            office.Website = $("#office-website").val();
            office.Email = $("#office-email").val();
            office.Address = $("#office-address").val();
            office.MondayFrom = $("#monday-from").val();
            office.MondayTo = $("#monday-to").val();
            office.TuesdayFrom = $("#tuesday-from").val();
            office.TuesdayTo = $("#tuesday-to").val();
            office.WednesdayFrom = $("#wednesday-from").val();
            office.WednesdayTo = $("#wednesday-to").val();
            office.ThursdayFrom = $("#thursday-from").val();
            office.ThursdayTo = $("#thursday-to").val();
            office.FridayFrom = $("#friday-from").val();
            office.FridayTo = $("#friday-to").val();
            office.SaturdayFrom = $("#saturday-from").val();
            office.SaturdayTo = $("#saturday-to").val();
            office.SundayFrom = $("#sunday-from").val();
            office.SundayTo = $("#sunday-to").val();
            if (self.currentOfficeId() && self.currentOfficeId().indexOf("office") == -1) {
                office.Id = self.currentOfficeId();
                for (var i = 0; i < self.offices().length; i++) {
                    if (self.offices()[i].Id() == self.currentOfficeId()) {
                        self.offices()[i].Name(office.Name);
                        self.offices()[i].Type(office.Type);
                        self.offices()[i].Phone(office.Phone);
                        self.offices()[i].PhoneDob(office.PhoneDob);
                        self.offices()[i].Fax(office.Fax);
                        self.offices()[i].FaxDob(office.FaxDob);
                        self.offices()[i].Address(office.Address);
                    }
                }
                AddingOffices.push(office);
            }
            else {
                if (self.isNewOffice()) {
                    office.Id = "office" + self.CountNewAddingOffice();
                    self.offices.push(new Office(office));
                    AddingOffices.push(office);
                    self.CountNewAddingOffice(self.CountNewAddingOffice() + 1);
                    self.isNewOffice(false);
                }
                else {
                    for (var j = 0; j < AddingOffices.length; j++) {
                        if (AddingOffices[j].Id == self.currentOfficeId()) {
                            AddingOffices[j].Name = office.Name;
                            AddingOffices[j].Type = office.Type;
                            AddingOffices[j].Phone = office.Phone;
                            AddingOffices[j].PhoneDob = office.PhoneDob;
                            AddingOffices[j].Fax = office.Fax;
                            AddingOffices[j].FaxDob = office.FaxDob;
                            AddingOffices[j].Website = office.Website;
                            AddingOffices[j].Email = office.Email;
                            AddingOffices[j].Address = office.Address;
                            AddingOffices[j].MondayFrom = office.MondayFrom;
                            AddingOffices[j].MondayTo = office.MondayTo;
                            AddingOffices[j].TuesdayFrom = office.TuesdayFrom;
                            AddingOffices[j].TuesdayTo = office.TuesdayTo;
                            AddingOffices[j].WednesdayFrom = office.WednesdayFrom;
                            AddingOffices[j].WednesdayTo = office.WednesdayTo; ;
                            AddingOffices[j].ThursdayFrom = office.ThursdayFrom;
                            AddingOffices[j].ThursdayTo = office.ThursdayTo;
                            AddingOffices[j].FridayFrom = office.FridayFrom;
                            AddingOffices[j].FridayTo = office.FridayTo;
                            AddingOffices[j].SaturdayFrom = office.SaturdayFrom;
                            AddingOffices[j].SaturdayTo = office.SaturdayTo;
                            AddingOffices[j].SundayFrom = office.SundayFrom;
                            AddingOffices[j].SundayTo = office.SundayTo;
                        }
                    }
                    for (var k = 0; k < self.offices().length; k++) {
                        if (self.offices()[k].Id() == self.currentOfficeId()) {
                            self.offices()[k].Name(office.Name);
                            self.offices()[k].Type(office.Type);
                            self.offices()[k].Phone(office.Phone);
                            self.offices()[k].PhoneDob(office.PhoneDob);
                            self.offices()[k].Fax(office.Fax);
                            self.offices()[k].FaxDob(office.FaxDob);
                            self.offices()[k].Address(office.Address);
                        }
                    }

                }
            }

            allCheckboxes = $("[name='officeitem']");
            $("#edit-office").modal("hide");
        };

        self.newOffice = function () {
            $("#edit-office input").val("");
            $("#edit-office select").val("");
            $("#edit-office textarea").val("");
            self.isNewOffice(true);
            self.currentOfficeId("");
            $("#edit-office").modal("show");
        };

        self.deleteOffice = function (office) {
            if (office.Id().indexOf("office") == -1) {
                DeleteOfficesId.push(office.Id());
            }
            if (office.Id().indexOf("office") >= 0) {
                for (var j = 0; j < AddingOffices.length; j++) {
                    if (AddingOffices[j].Id == office.Id()) {
                        AddingOffices.splice(j, 1);
                    }
                }
            }
            for (var i = 0; i < self.offices().length; i++) {
                if (self.offices()[i].Id() == office.Id()) {
                    self.offices.splice(i, 1);
                }
            };
        };

        self.deleteOffices = function () {
            var delId = $("[name='officeitem']:checked");
            for (var i = 0; i < delId.length; i++) {
                if (delId.eq(i).val().indexOf("office") == -1) {
                    DeleteOfficesId.push(delId.eq(i).val());
                }
                if (delId.eq(i).val().indexOf("office") >= 0) {
                    for (var p = 0; p < AddingOffices.length; p++) {
                        if (AddingOffices[p].Id == delId.eq(i).val()) {
                            AddingOffices.splice(p, 1);
                        }
                    }
                }
                for (var j = 0; j < self.offices().length; j++) {
                    if (self.offices()[j].Id() == delId.eq(i).val()) {
                        self.offices.splice(j, 1);
                    }
                };
            }
        };

        self.getOffice = function (off) {
            self.currentOfficeId(off.Id());
            if (off.Id() && off.Id().indexOf("office") == -1) {
                $.ajax({
                    url: '@Url.Action("GetOffice", "Admin")',
                    type: "POST",
                    data: { officeId: off.Id() },
                    success: function (data) {
                        if (data.Id) {
                            AssignValues(data);
                            $("#edit-office").modal("show");
                        }
                    }
                });
            }
            else {
                for (var i = 0; i < AddingOffices.length; i++) {
                    if (AddingOffices[i].Id == off.Id()) {
                        AssignValues(AddingOffices[i]);
                        break;
                    }
                }
                $("#edit-office").modal("show");
            }
        };
    }
    function AssignValues(data) {
        $("#office-name").val(data.Name);
        $("#office-type").val(data.Type);
        $("#office-phone").val(data.Phone);
        $("#office-phonedob").val(data.PhoneDob);
        $("#office-fax").val(data.Fax);
        $("#office-faxdob").val(data.FaxDob);
        $("#office-website").val(data.Website);
        $("#office-email").val(data.Email);
        $("#office-address").val(data.Address);
        $("#monday-from").val(data.MondayFrom);
        $("#monday-to").val(data.MondayTo);
        $("#tuesday-from").val(data.TuesdayFrom);
        $("#tuesday-to").val(data.TuesdayTo);
        $("#wednesday-from").val(data.WednesdayFrom);
        $("#wednesday-to").val(data.WednesdayTo);
        $("#thursday-from").val(data.ThursdayFrom);
        $("#thursday-to").val(data.ThursdayTo);
        $("#friday-from").val(data.FridayFrom);
        $("#friday-to").val(data.FridayTo);
        $("#saturday-from").val(data.SaturdayFrom);
        $("#saturday-to").val(data.SaturdayTo);
        $("#sunday-from").val(data.SundayFrom);
        $("#sunday-to").val(data.SundayTo);

    }
    $(function () {
        var viewModel = new MyViewModel();
        viewModel.addOffices();
        ko.applyBindings(viewModel);
        allCheckboxes = $("#partner-offices [name='officeitem']");
    });
    function DeleteAvatar() {
        if ($("#NewClientId").val()) {
            $.ajax({
                url: '@Url.Action("DeleteClientAvatar", "Upload")',
                type: "POST",
                data: { userId: $("#NewClientId").val() },
                success: function (data) {
                    if (data == "ok") {
                        $('#avatar').attr("src", "http://placehold.it/250x290");
                    }
                }
            });
        }
        $('#avatar').attr("src", "http://placehold.it/250x290");
        $("#avatarUpload").replaceWith("<input type='file' accept='image/jpeg' onchange='readURL(this);' class='hide' name='avatarUpload' id='avatarUpload' />");
    }
    function ChangeCheckPrtn() {
        allCheckboxes = $("#" + $("div.tab-pane.active").attr("id") + " tbody input[type=checkbox]");
        var notCheck = allCheckboxes.not(":checked");
        if (notCheck.length > 0) {
            $("#" + $("div.tab-pane.active").attr("id") + " #inlineCheckbox01").removeAttr("checked");
        }
        else {
            $("#" + $("div.tab-pane.active").attr("id") + " #inlineCheckbox01").attr("checked", "checked");
        }
    }

    function ChangeAllCheckPrtn() {
        allCheckboxes = $("#" + $("div.tab-pane.active").attr("id") + " tbody input[type=checkbox]");
        if (!$("#" + $("div.tab-pane.active").attr("id") + " #inlineCheckbox01").is(":checked")) {
            allCheckboxes.removeAttr("checked");
        }
        else {
            allCheckboxes.attr("checked", "checked");
        }
    }
</script>
<div class="row-fluid">
    <div class="span3">
        @{ Html.RenderPartial("_ButtonCreate"); }
    </div>
    <div class="span9">
        <div class="page-header">
            <h2>
                Партнеры</h2>
        </div>
        <div class="tabbable">
            <ul class="nav nav-tabs">
                <li class="active"><a href="#profile" data-toggle="tab">Профиль</a></li>
                <li><a href="#requisites" data-toggle="tab">Реквизиты</a></li>
                <li><a href="#partner-offices" data-toggle="tab">Офисы</a></li>
                <li><a href="#partner-products" data-toggle="tab">Продукты</a></li>
                <li><a href="#">Партнеры</a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active" id="profile">
                    <div class="row-fluid">
                        @using (Html.BeginForm("FormPartner", "Admin", FormMethod.Post, new { @class = "form-horizontal", id = "form1", enctype = "multipart/form-data" }))
                        {                              
                            <div class="span8">
                                @Html.HiddenFor(x => x.Id)
                                <fieldset>
                                    <legend>Основные данные</legend>
                                    <div class="control-group">
                                        <label class="control-label" for="Type">
                                            Вид</label>
                                        <div class="controls">
                                            @Html.DropDownListFor(x => x.Type, Model.ListForType, new { @class = "input-large" })
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label" for="Name">
                                            Название</label>
                                        <div class="controls">
                                            @Html.TextBoxFor(x => x.Name, new { @class = "input-large", placeholder = "Без кавычек" })
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label" for="FoundationYear">
                                            Год основания</label>
                                        <div class="controls">
                                            @Html.TextBoxFor(x => x.FoundationYear, new { @class = "input-mini date-year", type = "date" })
                                        </div>
                                    </div>
                                </fieldset>
                                <fieldset>
                                    <legend>Контактная информация</legend>
                                    <div class="control-group">
                                        <label class="control-label" for="Phone">
                                            Телефон</label>
                                        <div class="controls">
                                            @Html.TextBoxFor(x => x.Phone, new { @class = "input-large phone", type = "tel" })
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label" for="Fax">
                                            Факс</label>
                                        <div class="controls">
                                            @Html.TextBoxFor(x => x.Fax, new { @class = "input-large phone", type = "tel" })
                                            @Html.TextBoxFor(x => x.FaxDob, new { @class = "input-mini", type = "tel", placeholder = "доб." })
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label" for="Website">
                                            Веб-сайт</label>
                                        <div class="controls">
                                            @Html.TextBoxFor(x => x.Website, new { @class = "input-large", placeholder = "www.azb24.ru" })
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label" for="Email">
                                            Электронная почта</label>
                                        <div class="controls">
                                            @Html.TextBoxFor(x => x.Email, new { @class = "input-large", type = "email" })
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label" for="Socnetwork">
                                            Соцсеть</label>
                                        <div class="controls">
                                            @Html.TextBoxFor(x => x.Socnetwork, new { @class = "input-large", placeholder = "Номер страницы или ID" })
                                            @Html.DropDownListFor(x => x.TypeSocnetwork, Model.ListForSocnetwork, new { @class = "input-medium" })
                                        </div>
                                    </div>
                                </fieldset>
                                <div class="form-actions">
                                    <button class="btn btn-primary btn-large" type="button" onclick="FormSubmit();">
                                        Сохранить и изменения</button>
                                </div>
                            </div>
                            <div class="span4">
                                <div class="thumbnail">
                                    <img src="@(string.IsNullOrEmpty(Model.Avatar) || Model.Avatar.Equals("0") ? @"http://placehold.it/250x290" : Url.Image(Model.Avatar, 250, 290))"  id="avatar" alt="">
                                    <div class="caption">
                                        <div class="btn-group">
                                            <button type="button" class="btn " onclick="$('#avatarUpload').click()">
                                                Изменить фото</button>
                                            <button class="btn" rel="tooltip" type="button" title="Удалить фотографию" onclick="DeleteAvatar();">
                                                <i class="icon-trash"></i>
                                            </button>
                                            <input type="file" class="hide" accept="image/jpeg" onchange="readURL(this);" name="avatarUpload"
                                                id="avatarUpload" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                        }
                    </div>
                </div>
                <div class="tab-pane" id="requisites">
                    <div class="row-fluid">
                        <div class="span8 offset4">
                            <form class="form-horizontal">
                            <fieldset>
                                <div class="control-group">
                                    <label class="control-label" for="FullName">
                                        Полное наменование</label>
                                    <div class="controls">
                                        @Html.TextBoxFor(x => x.FullName, new { @class = "input-xlarge" })
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="TypeOwnership">
                                        Форма собственности</label>
                                    <div class="controls">
                                        @Html.DropDownListFor(x => x.TypeOwnership, Model.ListForTypeOwnership, new { @class = "input-small" })
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="PhoneRequisite">
                                        Телефон</label>
                                    <div class="controls">
                                        @Html.TextBoxFor(x => x.PhoneRequisite, new { @class = "input-xlarge phone", type = "tel" })
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="FaxRequisite">
                                        Факс</label>
                                    <div class="controls">
                                        @Html.TextBoxFor(x => x.FaxRequisite, new { @class = "input-xlarge phone", type = "tel" })
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="JuridicalAddress">
                                        Юридический адрес</label>
                                    <div class="controls">
                                        @Html.TextAreaFor(x => x.JuridicalAddress, new { @class = "input-xlarge", placeholder = "Индекс, страна, город, улица, дом " })
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="ActualAddress">
                                        Фактический адрес</label>
                                    <div class="controls">
                                        @Html.TextAreaFor(x => x.ActualAddress, new { @class = "input-xlarge", placeholder = "Индекс, страна, город, улица, дом " })
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="Inn">
                                        ИНН</label>
                                    <div class="controls">
                                        @Html.TextBoxFor(x => x.Inn, new { @class = "input-xlarge inn", placeholder = "10 или 12 цифр" })
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="Kpp">
                                        КПП</label>
                                    <div class="controls">
                                        @Html.TextBoxFor(x => x.Kpp, new { @class = "input-xlarge kpp", placeholder = "9 цифр" })
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="Okpo">
                                        ОКПО</label>
                                    <div class="controls">
                                        @Html.TextBoxFor(x => x.Okpo, new { @class = "input-xlarge okpo", placeholder = "8 или 10 цифр" })
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="PaymentAccount">
                                        Расчетный счет</label>
                                    <div class="controls">
                                        @Html.TextBoxFor(x => x.PaymentAccount, new { @class = "input-xlarge rs", placeholder = "20 цифр" })
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="CorrespondentAccount">
                                        Кор. счет</label>
                                    <div class="controls">
                                        @Html.TextBoxFor(x => x.CorrespondentAccount, new { @class = "input-xlarge ks", placeholder = "20 цифр" })
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="Bik">
                                        БИК</label>
                                    <div class="controls">
                                        @Html.TextBoxFor(x => x.Bik, new { @class = "input-xlarge bik", placeholder = "9 цифр" })
                                    </div>
                                </div>
                            </fieldset>
                            <div class="form-actions">
                                <button class="btn btn-primary btn-large" type="button" onclick="FormSubmit();">
                                    Сохранить и изменения</button>
                            </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="tab-pane" id="partner-offices">
                    <table class="table table-bordered table-striped" id="offices">
                        <thead>
                            <tr>
                                <th class="col-1">
                                    <input type="checkbox" onclick="ChangeAllCheckPrtn(this);" id="inlineCheckbox01"
                                        value="option0" title="Выделить все">
                                </th>
                                <th>
                                    Название
                                </th>
                                <th>
                                    Адрес
                                </th>
                                <th>
                                    Телефон
                                </th>
                                <th>
                                    Инструменты
                                </th>
                            </tr>
                        </thead>
                        <tbody data-bind="foreach: offices">
                            <tr>
                                <td class="col-1">
                                    <input type="checkbox" onchange="ChangeCheckPrtn();" name="officeitem" data-bind="attr: {value: Id()}">
                                </td>
                                <td>
                                    <a data-bind="text: Type() +' '+  Name()" href="#"></a>
                                </td>
                                <td>
                                    <a data-bind="text: Address(), attr: {href: 'http://maps.yandex.ru/?text=' + Address() }"
                                        target="_blank"></a>
                                </td>
                                <td>
                                    <ul class="unstyled">
                                        <li data-bind="text: Phone() + (PhoneDob() ? ' Доб. ' + PhoneDob() : '')"></li>
                                        <li data-bind="text: Fax() + (FaxDob() ? ' Доб. '  + FaxDob() : '')"></li>
                                    </ul>
                                </td>
                                <td>
                                    <div class="btn-group">
                                        <button class="btn" data-toggle="modal" href="#fin-record" rel="tooltip" title="Редактировать"
                                            data-bind="click:$root.getOffice">
                                            <i class="icon-edit"></i>
                                        </button>
                                        <button class="btn" data-toggle="modal" href="#fin-record" rel="tooltip" title="Удалить"
                                            data-bind="click: $root.deleteOffice">
                                            <i class="icon-trash"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="100%">
                                    <div class="table-toolbar">
                                        <div class="quant-item pull-left">
                                            @Html.DropDownListFor(x => x.PageSize, Model.ListForPageSize, new { @class = "input-mini", onchange = "ChangePageSize();" })
                                            <span class="help-inline">записей на странице</span>
                                        </div>
                                        <div class="pagination pagination-right">
                                            <ul>
                                                @Html.Paging(Model.PageNumber, Model.PageCount, i => Url.Action("FormPartner", "Admin", new { id = Model.Id, page = i, pagesize, ppage = Model.PageNumberProducts, ppagesize }))
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                    <button class="btn btn-success" data-toggle="modal" data-bind="click: newOffice ">
                        Добавить запись</button>
                    <button class="btn" data-bind="click: deleteOffices">
                        Удалить</button>
                    <div class="form-actions">
                        <button class="btn btn-primary btn-large" type="button" onclick="FormSubmit();">
                            Сохранить и изменения</button>
                    </div>
                </div>
                <div class="tab-pane" id="partner-products">
                    <table class="table table-bordered table-striped" id="products">
                        <thead>
                            <tr>
                                <th class="col-1">
                                    <input type="checkbox" id="inlineCheckbox01" onchange="ChangeAllCheckPrtn();" value="option0"
                                        title="Выделить все">
                                </th>
                                <th>
                                    Вид
                                </th>
                                <th>
                                    Программа
                                </th>
                                <th>
                                    Инструменты
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @using (Html.BeginForm("DeleteProducts", "Admin", FormMethod.Post, new { id = "form3" }))
                            {
                                @Html.HiddenFor(x => x.Id)
                                foreach (var product in Model.Products)
                                {
                                <tr>
                                    <td class="col-1">
                                        <input type="checkbox" onchange="ChangeCheckPrtn();" name="productitem" value="@product.Id">
                                    </td>
                                    <td>
                                        <a href="#">@product.Type</a>
                                    </td>
                                    <td>
                                        <a href="#" target="_blank">@product.Programm</a>
                                    </td>
                                    <td>
                                        <div class="btn-group">
                                            <button class="btn" data-toggle="modal" rel="tooltip" title="Редактировать" onclick="location.href='@Url.Action("FormProduct", "Admin", new { id = product.Id })'">
                                                <i class="icon-edit"></i>
                                            </button>
                                            <button class="btn" data-toggle="modal" rel="tooltip" onclick="DeleteProduct(this);"
                                                title="Удалить">
                                                <i class="icon-trash"></i>
                                            </button>
                                        </div>
                                    </td>
                                </tr>
                                }
                            }
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="100%">
                                    <div class="table-toolbar">
                                        <div class="quant-item pull-left">
                                            @Html.DropDownListFor(x => x.PPageSize, Model.ListForPageSize, new { @class = "input-mini", onchange = "ChangePageSize();" })
                                            <span class="help-inline">записей на странице</span>
                                        </div>
                                        <div class="pagination pagination-right">
                                            <ul>
                                                @Html.Paging(Model.PageNumberProducts, Model.PageCountProducts, i => Url.Action("FormPartner", "Admin", new { id = Model.Id, page = Model.PageNumber, pagesize, ppage = i, ppagesize }))
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                    <button class="btn btn-primary" data-toggle="modal" onclick="location.href = '@Url.Action("FormProduct", "Admin", new { id = "", partnerId = Model.Id })'">
                        Добавить запись</button>
                    <button class="btn" onclick="$('#form3').submit();">
                        Удалить</button>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal hide " id="edit-office">
    <div class="modal-header">
        <button data-dismiss="modal" class="close">
            ×</button>
        <h3>
            Офис партнера</h3>
    </div>
    <div class="modal-body">
        <form class="form-horizontal">
        <fieldset>
            <legend>Основные данные</legend>
            <div class="control-group">
                <label class="control-label" for="office-name">
                    Название</label>
                <div class="controls">
                    <input type="text" class="input-large" id="office-name" placeholder="">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="office-type">
                    Тип</label>
                <div class="controls">
                    <select class="input-large" id="office-type">
                        <option value="Офис продаж">Офис продаж</option>
                        <option value="Терминал">Терминал</option>
                    </select>
                </div>
            </div>
        </fieldset>
        <fieldset>
            <legend>Контактная информация</legend>
            <div class="control-group">
                <label class="control-label" for="office-phone">
                    Телефон</label>
                <div class="controls">
                    <input type="tel" class="input-large phone" id="office-phone">
                    <input type="tel" class="input-mini" placeholder="доб." id="office-phonedob">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="office-fax">
                    Факс</label>
                <div class="controls">
                    <input type="tel" class="input-large phone" id="office-fax">
                    <input type="tel" class="input-mini" placeholder="доб." id="office-faxdob">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="office-website">
                    Веб-сайт</label>
                <div class="controls">
                    <input type="tel" class="input-large" id="office-website" placeholder="www.azb24.ru">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="office-email">
                    Электронная почта</label>
                <div class="controls">
                    <input type="email" class="input-large" id="office-email">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="office-address">
                    Адрес</label>
                <div class="controls">
                    <textarea class="input-large" id="office-address" placeholder="Город, улица, дом "></textarea>
                </div>
            </div>
        </fieldset>
        <fieldset>
            <legend>Время работы</legend>
            <div class="control-group">
                <label class="control-label">
                    Понедельник</label>
                <div class="controls">
                    <span class="help-inline">c</span>
                    <input class="time input-mini" type="text" id="monday-from"><span class="help-inline">до</span>
                    <input class="time input-mini" type="text" id="monday-to">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    Вторник</label>
                <div class="controls">
                    <span class="help-inline">c</span>
                    <input class="time input-mini"  id="tuesday-from"><span class="help-inline">до</span>
                    <input class="time input-mini"  id="tuesday-to">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    Среда</label>
                <div class="controls">
                    <span class="help-inline">c</span>
                    <input class="time input-mini" type="text" id="wednesday-from"><span class="help-inline">до</span>
                    <input class="time input-mini" type="text" id="wednesday-to">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    Четверг</label>
                <div class="controls">
                    <span class="help-inline">c</span>
                    <input class="time input-mini" type="text" id="thursday-from"><span class="help-inline">до</span>
                    <input class="time input-mini" type="text" id="thursday-to">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    Пятница</label>
                <div class="controls">
                    <span class="help-inline">c</span>
                    <input class="time input-mini" type="text" id="friday-from"><span class="help-inline">до</span>
                    <input class="time input-mini" type="text" id="friday-to">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    Суббота</label>
                <div class="controls">
                    <span class="help-inline">c</span>
                    <input class="time input-mini" type="text" id="saturday-from"><span class="help-inline">до</span>
                    <input class="time input-mini" type="text" id="saturday-to">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    Воскресение</label>
                <div class="controls">
                    <span class="help-inline">c</span>
                    <input class="time input-mini" type="text" id="sunday-from"><span class="help-inline">до</span>
                    <input class="time input-mini" type="text" id="sunday-to">
                </div>
            </div>
        </fieldset>
        </form>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" data-bind="click:addOffice">
            Сохранить и изменения</button>
        <!--button data-dismiss="modal" class="btn">Закрыть окно</button-->
    </div>
</div>
